home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE20 / EX2.C < prev    next >
C/C++ Source or Header  |  1995-03-22  |  4KB  |  69 lines

  1. #define LISTBOX_ID             1000   // Identifies the child window.
  2.  
  3. #include <genstub.c>
  4.  
  5. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.    switch (uMsg) 
  8.    {
  9.          case WM_CREATE:   // Create list box child window to show section keys.
  10.             {
  11.                RECT    rectClient;
  12.                LRESULT lRetVal = DefWindowProc(hWnd, uMsg, wParam, lParam);
  13.                GetClientRect( hWnd, &rectClient );       // Use client rectangle to center child.
  14.                CreateWindow( "listbox",                               // listbox class
  15.                              "child listbox",                         // name
  16.                              WS_CHILD | WS_VISIBLE | LBS_STANDARD,    // style
  17.                              10, 10,                                  // location
  18.                              rectClient.right - rectClient.left - 20, // width
  19.                              rectClient.bottom - rectClient.top - 20, // height
  20.                              hWnd,                                    // parent
  21.                              (HMENU) LISTBOX_ID,                      // child window ID
  22.                              hInst,                                   // app instance
  23.                              NULL );                                  // special parameters 
  24.                return lRetVal;
  25.             } 
  26.          case WM_COMMAND:       // process menu items 
  27.                  switch ( LOWORD( wParam )  )
  28.                  {
  29.                      case IDM_TEST:  // Fill the list box child with section data.
  30.                         { 
  31.                            LPTSTR lpTemp;    
  32.                            HWND   hWndListBox = GetDlgItem( hWnd, LISTBOX_ID );
  33.                            if ( hWndListBox ) 
  34.                            {
  35.                               LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
  36.                                                                     HEAP_ZERO_MEMORY,
  37.                                                                     0x7fff ); 
  38.                               SendMessage( hWndListBox, LB_RESETCONTENT, 0, 0 );
  39.                               GetPrivateProfileSection( "groups",           // segment  
  40.                                                         lpIniValuesBuffer,  // buffer
  41.                                                         0x7fff,             // buffer size
  42.                                                         "progman.ini");     // program manager
  43.                               // Fill list box until the end of the buffer.
  44.                               lpTemp = lpIniValuesBuffer;
  45.                               while ( *lpTemp ) 
  46.                               {
  47.                                  SendMessage( hWndListBox, LB_ADDSTRING, 0, (LPARAM) lpTemp ); 
  48.                                  lpTemp += (lstrlen(lpTemp) + 1); // jump past null
  49.                               }
  50.                               HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
  51.                            } 
  52.                         }
  53.                      break;
  54.                      case IDM_EXIT: 
  55.                         DestroyWindow( hWnd );
  56.                         break;
  57.                  }
  58.                  break;
  59.          case WM_DESTROY: 
  60.                  PostQuitMessage( 0 );
  61.                  break;
  62.          default:
  63.                  return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  64.     }
  65.     return (NULL);
  66. }
  67.  
  68. #include <about.c>
  69.